package com.liuyang.demo.zookeeper;

import org.apache.zookeeper.CreateMode;
import org.apache.zookeeper.ZooDefs;
import org.apache.zookeeper.ZooKeeper;

public class Connect {
    public static void main(String[] args) throws Exception {


        ZooKeeper zk = new ZooKeeper("192.168.217.15:2181", 100000, null);

        ZooKeeper.States state = zk.getState();
        if(state.isAlive()){
            System.out.printf("Alive !");
        }
        System.out.println(zk.getClass());
        if(zk.exists("/test", false) == null)
        {
            zk.create("/test", "znode1".getBytes(), ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
        }
        System.out.println(new String(zk.getData("/test", false, null)));
    }
}
